﻿namespace Probel.NDoctor.Statistics.UnitTests
{
    using System;

    using NUnit.Framework;

    using Probel.NDoctor.Statistics.UnitTests.Helpers;

    [TestFixture]
    public abstract class BaseScalarQuery
    {
        #region Fields

        private readonly IFactory Factory;
        private readonly IScalarQuery Scalars;
        private readonly DateTime Today = Data.Today;

        #endregion Fields

        #region Constructors

        protected BaseScalarQuery(IFactory factory)
        {
            this.Factory = factory;
            this.Scalars = this.Factory.Scalars();
        }

        #endregion Constructors

        #region Methods

        [Test]
        public void Count_ActiveUsers_5ActiveApplications()
        {
            var count = this.Scalars.GetActiveApplicationCount();
            Assert.AreEqual(4, count);
        }

        [Test]
        public void Count_Statistics_10Entries()
        {
            var count = this.Scalars.GetStatisticsCount();
            Assert.AreEqual(10, count);
        }

        [Test]
        public void Count_Users_6Users()
        {
            var count = this.Scalars.GetApplicationCount();
            Assert.AreEqual(6, count);
        }

        [Test]
        public void GetApplication_ByAppKey_AppFound()
        {
            var app = this.Scalars.GetApplicationByAppKey(Data.AppKey);
            Assert.AreEqual(new Version(1, 2, 3, 4), new Version(app.Version));
        }

        [Test]
        public void GetAverage_ExecutionTime_10IsExpected()
        {
            var avg = this.Scalars.GetAvgExecutionTime();
            Assert.AreEqual(10, avg);
        }

        [Test]
        public void GetDate_OfFirstInstallation_15DaysFromToday()
        {
            var first = this.Scalars.GetFirstInstallation();
            Assert.AreEqual(Today.AddDays(-15), first);
        }

        [Test]
        public void GetDate_OfLastInstallation_10DaysFromToday()
        {
            var last = this.Scalars.GetLastInstallation();
            Assert.AreEqual(Today.AddDays(-10), last);
        }

        [Test]
        public void GetDate_OfLastUpdate_10DaysFromToday()
        {
            var first = this.Scalars.GetLastUpdate();
            Assert.AreEqual(Today.AddDays(-10), first);
        }

        #endregion Methods
    }
}